home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / BasicComboBoxEditor.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  110 lines

  1. /*
  2.  * @(#)BasicComboBoxEditor.java    1.7 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.plaf.basic;
  21.  
  22. import com.sun.java.swing.*;
  23. import com.sun.java.swing.border.*;
  24. import java.io.Serializable;
  25. import java.awt.*;
  26. import java.awt.event.*;
  27.  
  28. /**
  29.  * The default editor for editable combo boxes
  30.  * <p>
  31.  * Warning: serialized objects of this class will not be compatible with
  32.  * future swing releases.  The current serialization support is appropriate 
  33.  * for short term storage or RMI between Swing1.0 applications.  It will
  34.  * not be possible to load serialized Swing1.0 objects with future releases
  35.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  36.  * baseline for the serialized form of Swing objects.
  37.  *
  38.  * @version 1.7 02/02/98
  39.  * @author Arnaud Weber
  40.  */
  41. public class BasicComboBoxEditor implements ComboBoxEditor,FocusListener, Serializable {
  42.     protected JTextField editor;
  43.  
  44.     public BasicComboBoxEditor() {
  45.         editor = new BorderlessTextField("",9);
  46.         editor.addFocusListener(this);
  47.         editor.setBorder(null);
  48.     }
  49.  
  50.     public Component getEditorComponent() {
  51.         return editor;
  52.     }
  53.  
  54.     public void setItem(Object anObject) {
  55.         if(anObject != null)
  56.             editor.setText(anObject.toString());
  57.         else
  58.             editor.setText("");
  59.     }
  60.  
  61.     public Object getItem() {
  62.         return editor.getText();
  63.     }
  64.  
  65.     public void selectAll() {
  66.         editor.selectAll();
  67.         editor.requestFocus();
  68.     }
  69.  
  70.     public void focusGained(FocusEvent e) {}
  71.     public void focusLost(FocusEvent e) {
  72.         editor.postActionEvent();
  73.     }
  74.  
  75.     public void addActionListener(ActionListener l) {
  76.         editor.addActionListener(l);
  77.     }
  78.  
  79.     public void removeActionListener(ActionListener l) {
  80.         editor.removeActionListener(l);
  81.     }
  82.  
  83.     static class BorderlessTextField extends JTextField {
  84.         public BorderlessTextField(String value,int n) {
  85.             super(value,n);
  86.         }
  87.  
  88.         public void setBorder(Border b) {}
  89.     }
  90.  
  91.     /**
  92.      * A subclass of BasicComboBoxEditor that implements UIResource.
  93.      * BasicComboBoxEditor doesn't implement UIResource
  94.      * directly so that applications can safely override the
  95.      * cellRenderer property with BasicListCellRenderer subclasses.
  96.      * <p>
  97.      * Warning: serialized objects of this class will not be compatible with
  98.      * future swing releases.  The current serialization support is appropriate
  99.      * for short term storage or RMI between Swing1.0 applications.  It will
  100.      * not be possible to load serialized Swing1.0 objects with future releases
  101.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  102.      * baseline for the serialized form of Swing objects.
  103.      */
  104.     public static class UIResource extends BasicComboBoxEditor
  105.         implements com.sun.java.swing.plaf.UIResource
  106.     {
  107.     }
  108. }
  109.  
  110.